﻿using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using HslCommunication.BasicFramework;
using HslCommunication.Core;
using HslCommunication.Core.Address;
using HslCommunication.Core.Net;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.Melsec
{
	/// <summary>
	/// 基于Qna 兼容3C帧的格式一的通讯，具体的地址需要参照三菱的基本地址，本类是基于tcp通讯的实现<br />
	/// Based on Qna-compatible 3C frame format one communication, the specific address needs to refer to the basic address of Mitsubishi. This class is based on TCP communication.
	/// </summary>
	/// <remarks>
	/// 地址可以携带站号信息，例如：s=2;D100
	/// </remarks>
	/// <example>
	/// 地址的输入的格式说明如下：
	/// <list type="table">
	///   <listheader>
	///     <term>地址名称</term>
	///     <term>地址代号</term>
	///     <term>示例</term>
	///     <term>地址进制</term>
	///     <term>字操作</term>
	///     <term>位操作</term>
	///     <term>备注</term>
	///   </listheader>
	///   <item>
	///     <term>内部继电器</term>
	///     <term>M</term>
	///     <term>M100,M200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>输入继电器</term>
	///     <term>X</term>
	///     <term>X100,X1A0</term>
	///     <term>16</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>输出继电器</term>
	///     <term>Y</term>
	///     <term>Y100,Y1A0</term>
	///     <term>16</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///    <item>
	///     <term>锁存继电器</term>
	///     <term>L</term>
	///     <term>L100,L200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>报警器</term>
	///     <term>F</term>
	///     <term>F100,F200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>边沿继电器</term>
	///     <term>V</term>
	///     <term>V100,V200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>链接继电器</term>
	///     <term>B</term>
	///     <term>B100,B1A0</term>
	///     <term>16</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>步进继电器</term>
	///     <term>S</term>
	///     <term>S100,S200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>数据寄存器</term>
	///     <term>D</term>
	///     <term>D1000,D2000</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>链接寄存器</term>
	///     <term>W</term>
	///     <term>W100,W1A0</term>
	///     <term>16</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>文件寄存器</term>
	///     <term>R</term>
	///     <term>R100,R200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>ZR文件寄存器</term>
	///     <term>ZR</term>
	///     <term>ZR100,ZR2A0</term>
	///     <term>16</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>变址寄存器</term>
	///     <term>Z</term>
	///     <term>Z100,Z200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>定时器的触点</term>
	///     <term>TS</term>
	///     <term>TS100,TS200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>定时器的线圈</term>
	///     <term>TC</term>
	///     <term>TC100,TC200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>定时器的当前值</term>
	///     <term>TN</term>
	///     <term>TN100,TN200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>累计定时器的触点</term>
	///     <term>SS</term>
	///     <term>SS100,SS200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>累计定时器的线圈</term>
	///     <term>SC</term>
	///     <term>SC100,SC200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>累计定时器的当前值</term>
	///     <term>SN</term>
	///     <term>SN100,SN200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>计数器的触点</term>
	///     <term>CS</term>
	///     <term>CS100,CS200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>计数器的线圈</term>
	///     <term>CC</term>
	///     <term>CC100,CC200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>计数器的当前值</term>
	///     <term>CN</term>
	///     <term>CN100,CN200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	/// </list>
	/// </example>
	// Token: 0x02000067 RID: 103
	public class MelsecA3CNet1OverTcp : NetworkDeviceSoloBase
	{
		/// <summary>
		/// 实例化默认的对象<br />
		/// Instantiate the default object
		/// </summary>
		// Token: 0x06000859 RID: 2137 RVA: 0x0002D256 File Offset: 0x0002B456
		public MelsecA3CNet1OverTcp()
		{
			base.WordLength = 1;
			base.ByteTransform = new RegularByteTransform();
		}

		/// <summary>
		/// 指定ip地址和端口号来实例化对象<br />
		/// Specify the IP address and port number to instantiate the object
		/// </summary>
		/// <param name="ipAddress">Ip地址信息</param>
		/// <param name="port">端口号信息</param>
		// Token: 0x0600085A RID: 2138 RVA: 0x0002D27B File Offset: 0x0002B47B
		public MelsecA3CNet1OverTcp(string ipAddress, int port)
		{
			base.WordLength = 1;
			this.IpAddress = ipAddress;
			this.Port = port;
			base.ByteTransform = new RegularByteTransform();
		}

		/// <inheritdoc />
		// Token: 0x1700017F RID: 383
		// (get) Token: 0x0600085B RID: 2139 RVA: 0x0002D2B0 File Offset: 0x0002B4B0
		// (set) Token: 0x0600085C RID: 2140 RVA: 0x0002D2B8 File Offset: 0x0002B4B8
		public byte Station
		{
			get
			{
				return this.station;
			}
			set
			{
				this.station = value;
			}
		}

		// Token: 0x0600085D RID: 2141 RVA: 0x0002D2C4 File Offset: 0x0002B4C4
		private OperateResult<byte[]> ReadWithPackCommand(byte[] command, byte station)
		{
			return base.ReadFromCoreServer(MelsecA3CNet1OverTcp.PackCommand(command, station));
		}

		// Token: 0x0600085E RID: 2142 RVA: 0x0002D2E4 File Offset: 0x0002B4E4
		[DebuggerStepThrough]
		private Task<OperateResult<byte[]>> ReadWithPackCommandAsync(byte[] command)
		{
			MelsecA3CNet1OverTcp.<ReadWithPackCommandAsync>d__6 <ReadWithPackCommandAsync>d__ = new MelsecA3CNet1OverTcp.<ReadWithPackCommandAsync>d__6();
			<ReadWithPackCommandAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadWithPackCommandAsync>d__.<>4__this = this;
			<ReadWithPackCommandAsync>d__.command = command;
			<ReadWithPackCommandAsync>d__.<>1__state = -1;
			<ReadWithPackCommandAsync>d__.<>t__builder.Start<MelsecA3CNet1OverTcp.<ReadWithPackCommandAsync>d__6>(ref <ReadWithPackCommandAsync>d__);
			return <ReadWithPackCommandAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 批量读取PLC的数据，以字为单位，支持读取X,Y,M,S,D,T,C，具体的地址范围需要根据PLC型号来确认<br />
		/// Read PLC data in batches, in units of words, supports reading X, Y, M, S, D, T, C. The specific address range needs to be confirmed according to the PLC model
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <param name="length">数据长度</param>
		/// <returns>读取结果信息</returns>
		// Token: 0x0600085F RID: 2143 RVA: 0x0002D330 File Offset: 0x0002B530
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			byte b = (byte)HslHelper.ExtractParameter(ref address, "s", (int)this.station);
			return MelsecA3CNet1OverTcp.ReadHelper(address, length, b, new Func<byte[], byte, OperateResult<byte[]>>(this.ReadWithPackCommand));
		}

		/// <summary>
		/// 批量写入PLC的数据，以字为单位，也就是说最少2个字节信息，支持X,Y,M,S,D,T,C，具体的地址范围需要根据PLC型号来确认<br />
		/// The data written to the PLC in batches is in units of words, that is, at least 2 bytes of information. It supports X, Y, M, S, D, T, and C. The specific address range needs to be confirmed according to the PLC model.
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <param name="value">数据值</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000860 RID: 2144 RVA: 0x0002D36C File Offset: 0x0002B56C
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			byte b = (byte)HslHelper.ExtractParameter(ref address, "s", (int)this.station);
			return MelsecA3CNet1OverTcp.WriteHelper(address, value, b, new Func<byte[], byte, OperateResult<byte[]>>(this.ReadWithPackCommand));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.Read(System.String,System.UInt16)" />
		// Token: 0x06000861 RID: 2145 RVA: 0x0002D3A8 File Offset: 0x0002B5A8
		[DebuggerStepThrough]
		public override Task<OperateResult<byte[]>> ReadAsync(string address, ushort length)
		{
			MelsecA3CNet1OverTcp.<ReadAsync>d__9 <ReadAsync>d__ = new MelsecA3CNet1OverTcp.<ReadAsync>d__9();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.address = address;
			<ReadAsync>d__.length = length;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<MelsecA3CNet1OverTcp.<ReadAsync>d__9>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.Write(System.String,System.Byte[])" />
		// Token: 0x06000862 RID: 2146 RVA: 0x0002D3FC File Offset: 0x0002B5FC
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, byte[] value)
		{
			MelsecA3CNet1OverTcp.<WriteAsync>d__10 <WriteAsync>d__ = new MelsecA3CNet1OverTcp.<WriteAsync>d__10();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<MelsecA3CNet1OverTcp.<WriteAsync>d__10>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 批量读取bool类型数据，支持的类型为X,Y,S,T,C，具体的地址范围取决于PLC的类型<br />
		/// Read bool data in batches. The supported types are X, Y, S, T, C. The specific address range depends on the type of PLC.
		/// </summary>
		/// <param name="address">地址信息，比如X10,Y17，注意X，Y的地址是8进制的</param>
		/// <param name="length">读取的长度</param>
		/// <returns>读取结果信息</returns>
		// Token: 0x06000863 RID: 2147 RVA: 0x0002D450 File Offset: 0x0002B650
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			byte b = (byte)HslHelper.ExtractParameter(ref address, "s", (int)this.station);
			return MelsecA3CNet1OverTcp.ReadBoolHelper(address, length, b, new Func<byte[], byte, OperateResult<byte[]>>(this.ReadWithPackCommand));
		}

		/// <summary>
		/// 批量写入bool类型的数组，支持的类型为X,Y,S,T,C，具体的地址范围取决于PLC的类型<br />
		/// Write arrays of type bool in batches. The supported types are X, Y, S, T, C. The specific address range depends on the type of PLC.
		/// </summary>
		/// <param name="address">PLC的地址信息</param>
		/// <param name="value">数据信息</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000864 RID: 2148 RVA: 0x0002D48C File Offset: 0x0002B68C
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] value)
		{
			byte b = (byte)HslHelper.ExtractParameter(ref address, "s", (int)this.station);
			return MelsecA3CNet1OverTcp.WriteHelper(address, value, b, new Func<byte[], byte, OperateResult<byte[]>>(this.ReadWithPackCommand));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.ReadBool(System.String,System.UInt16)" />
		// Token: 0x06000865 RID: 2149 RVA: 0x0002D4C8 File Offset: 0x0002B6C8
		[DebuggerStepThrough]
		public override Task<OperateResult<bool[]>> ReadBoolAsync(string address, ushort length)
		{
			MelsecA3CNet1OverTcp.<ReadBoolAsync>d__13 <ReadBoolAsync>d__ = new MelsecA3CNet1OverTcp.<ReadBoolAsync>d__13();
			<ReadBoolAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadBoolAsync>d__.<>4__this = this;
			<ReadBoolAsync>d__.address = address;
			<ReadBoolAsync>d__.length = length;
			<ReadBoolAsync>d__.<>1__state = -1;
			<ReadBoolAsync>d__.<>t__builder.Start<MelsecA3CNet1OverTcp.<ReadBoolAsync>d__13>(ref <ReadBoolAsync>d__);
			return <ReadBoolAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.Write(System.String,System.Boolean[])" />
		// Token: 0x06000866 RID: 2150 RVA: 0x0002D51C File Offset: 0x0002B71C
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool[] value)
		{
			MelsecA3CNet1OverTcp.<WriteAsync>d__14 <WriteAsync>d__ = new MelsecA3CNet1OverTcp.<WriteAsync>d__14();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<MelsecA3CNet1OverTcp.<WriteAsync>d__14>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecFxLinksOverTcp.StartPLC(System.String)" />
		// Token: 0x06000867 RID: 2151 RVA: 0x0002D56E File Offset: 0x0002B76E
		[HslMqttApi]
		public OperateResult RemoteRun()
		{
			return MelsecA3CNet1OverTcp.RemoteRunHelper(this.station, new Func<byte[], byte, OperateResult<byte[]>>(this.ReadWithPackCommand));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecFxLinksOverTcp.StopPLC(System.String)" />
		// Token: 0x06000868 RID: 2152 RVA: 0x0002D587 File Offset: 0x0002B787
		[HslMqttApi]
		public OperateResult RemoteStop()
		{
			return MelsecA3CNet1OverTcp.RemoteStopHelper(this.station, new Func<byte[], byte, OperateResult<byte[]>>(this.ReadWithPackCommand));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.ReadPlcType" />
		// Token: 0x06000869 RID: 2153 RVA: 0x0002D5A0 File Offset: 0x0002B7A0
		[HslMqttApi]
		public OperateResult<string> ReadPlcType()
		{
			return MelsecA3CNet1OverTcp.ReadPlcTypeHelper(this.station, new Func<byte[], byte, OperateResult<byte[]>>(this.ReadWithPackCommand));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.RemoteRun" />
		// Token: 0x0600086A RID: 2154 RVA: 0x0002D5BC File Offset: 0x0002B7BC
		[DebuggerStepThrough]
		public Task<OperateResult> RemoteRunAsync()
		{
			MelsecA3CNet1OverTcp.<RemoteRunAsync>d__18 <RemoteRunAsync>d__ = new MelsecA3CNet1OverTcp.<RemoteRunAsync>d__18();
			<RemoteRunAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<RemoteRunAsync>d__.<>4__this = this;
			<RemoteRunAsync>d__.<>1__state = -1;
			<RemoteRunAsync>d__.<>t__builder.Start<MelsecA3CNet1OverTcp.<RemoteRunAsync>d__18>(ref <RemoteRunAsync>d__);
			return <RemoteRunAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.RemoteStop" />
		// Token: 0x0600086B RID: 2155 RVA: 0x0002D600 File Offset: 0x0002B800
		[DebuggerStepThrough]
		public Task<OperateResult> RemoteStopAsync()
		{
			MelsecA3CNet1OverTcp.<RemoteStopAsync>d__19 <RemoteStopAsync>d__ = new MelsecA3CNet1OverTcp.<RemoteStopAsync>d__19();
			<RemoteStopAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<RemoteStopAsync>d__.<>4__this = this;
			<RemoteStopAsync>d__.<>1__state = -1;
			<RemoteStopAsync>d__.<>t__builder.Start<MelsecA3CNet1OverTcp.<RemoteStopAsync>d__19>(ref <RemoteStopAsync>d__);
			return <RemoteStopAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecA3CNet1OverTcp.ReadPlcType" />
		// Token: 0x0600086C RID: 2156 RVA: 0x0002D644 File Offset: 0x0002B844
		[DebuggerStepThrough]
		public Task<OperateResult<string>> ReadPlcTypeAsync()
		{
			MelsecA3CNet1OverTcp.<ReadPlcTypeAsync>d__20 <ReadPlcTypeAsync>d__ = new MelsecA3CNet1OverTcp.<ReadPlcTypeAsync>d__20();
			<ReadPlcTypeAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<string>>.Create();
			<ReadPlcTypeAsync>d__.<>4__this = this;
			<ReadPlcTypeAsync>d__.<>1__state = -1;
			<ReadPlcTypeAsync>d__.<>t__builder.Start<MelsecA3CNet1OverTcp.<ReadPlcTypeAsync>d__20>(ref <ReadPlcTypeAsync>d__);
			return <ReadPlcTypeAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x0600086D RID: 2157 RVA: 0x0002D688 File Offset: 0x0002B888
		public override string ToString()
		{
			return string.Format("MelsecA3CNet1OverTcp[{0}:{1}]", this.IpAddress, this.Port);
		}

		/// <summary>
		/// 批量读取PLC的数据，以字为单位，支持读取X,Y,M,S,D,T,C，具体的地址范围需要根据PLC型号来确认
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <param name="length">数据长度</param>
		/// <param name="station">当前PLC的站号信息</param>
		/// <param name="readCore">通信的载体信息</param>
		/// <returns>读取结果信息</returns>
		// Token: 0x0600086E RID: 2158 RVA: 0x0002D6A8 File Offset: 0x0002B8A8
		public static OperateResult<byte[]> ReadHelper(string address, ushort length, byte station, Func<byte[], byte, OperateResult<byte[]>> readCore)
		{
			OperateResult<McAddressData> operateResult = McAddressData.ParseMelsecFrom(address, length);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				byte[] arg = MelsecHelper.BuildAsciiReadMcCoreCommand(operateResult.Content, false);
				OperateResult<byte[]> operateResult2 = readCore(arg, station);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					bool flag3 = operateResult2.Content[0] != 2;
					if (flag3)
					{
						result = new OperateResult<byte[]>((int)operateResult2.Content[0], "Read Faild:" + Encoding.ASCII.GetString(operateResult2.Content, 1, operateResult2.Content.Length - 1));
					}
					else
					{
						byte[] array = new byte[(int)(length * 2)];
						for (int i = 0; i < array.Length / 2; i++)
						{
							ushort value = Convert.ToUInt16(Encoding.ASCII.GetString(operateResult2.Content, i * 4 + 11, 4), 16);
							BitConverter.GetBytes(value).CopyTo(array, i * 2);
						}
						result = OperateResult.CreateSuccessResult<byte[]>(array);
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 批量写入PLC的数据，以字为单位，也就是说最少2个字节信息，支持X,Y,M,S,D,T,C，具体的地址范围需要根据PLC型号来确认
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <param name="value">数据值</param>
		/// <param name="station">当前PLC的站号信息</param>
		/// <param name="readCore">通信的载体信息</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x0600086F RID: 2159 RVA: 0x0002D7B8 File Offset: 0x0002B9B8
		public static OperateResult WriteHelper(string address, byte[] value, byte station, Func<byte[], byte, OperateResult<byte[]>> readCore)
		{
			OperateResult<McAddressData> operateResult = McAddressData.ParseMelsecFrom(address, 0);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				byte[] arg = MelsecHelper.BuildAsciiWriteWordCoreCommand(operateResult.Content, value);
				OperateResult<byte[]> operateResult2 = readCore(arg, station);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					bool flag3 = operateResult2.Content[0] != 6;
					if (flag3)
					{
						result = new OperateResult((int)operateResult2.Content[0], "Write Faild:" + Encoding.ASCII.GetString(operateResult2.Content, 1, operateResult2.Content.Length - 1));
					}
					else
					{
						result = OperateResult.CreateSuccessResult();
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 批量读取bool类型数据，支持的类型为X,Y,S,T,C，具体的地址范围取决于PLC的类型
		/// </summary>
		/// <param name="address">地址信息，比如X10,Y17，注意X，Y的地址是8进制的</param>
		/// <param name="length">读取的长度</param>
		/// <param name="station">当前PLC的站号信息</param>
		/// <param name="readCore">通信的载体信息</param>
		/// <returns>读取结果信息</returns>
		// Token: 0x06000870 RID: 2160 RVA: 0x0002D864 File Offset: 0x0002BA64
		public static OperateResult<bool[]> ReadBoolHelper(string address, ushort length, byte station, Func<byte[], byte, OperateResult<byte[]>> readCore)
		{
			OperateResult<McAddressData> operateResult = McAddressData.ParseMelsecFrom(address, length);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				byte[] arg = MelsecHelper.BuildAsciiReadMcCoreCommand(operateResult.Content, true);
				OperateResult<byte[]> operateResult2 = readCore(arg, station);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<bool[]>(operateResult2);
				}
				else
				{
					bool flag3 = operateResult2.Content[0] != 2;
					if (flag3)
					{
						result = new OperateResult<bool[]>((int)operateResult2.Content[0], "Read Faild:" + Encoding.ASCII.GetString(operateResult2.Content, 1, operateResult2.Content.Length - 1));
					}
					else
					{
						byte[] array = new byte[(int)length];
						Array.Copy(operateResult2.Content, 11, array, 0, (int)length);
						result = OperateResult.CreateSuccessResult<bool[]>(Enumerable.ToArray<bool>(Enumerable.Select<byte, bool>(array, (byte m) => m == 49)));
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 批量写入bool类型的数组，支持的类型为X,Y,S,T,C，具体的地址范围取决于PLC的类型
		/// </summary>
		/// <param name="address">PLC的地址信息</param>
		/// <param name="value">数据信息</param>
		/// <param name="station">当前PLC的站号信息</param>
		/// <param name="readCore">通信的载体信息</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000871 RID: 2161 RVA: 0x0002D960 File Offset: 0x0002BB60
		public static OperateResult WriteHelper(string address, bool[] value, byte station, Func<byte[], byte, OperateResult<byte[]>> readCore)
		{
			OperateResult<McAddressData> operateResult = McAddressData.ParseMelsecFrom(address, 0);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				byte[] arg = MelsecHelper.BuildAsciiWriteBitCoreCommand(operateResult.Content, value);
				OperateResult<byte[]> operateResult2 = readCore(arg, station);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					bool flag3 = operateResult2.Content[0] != 6;
					if (flag3)
					{
						result = new OperateResult((int)operateResult2.Content[0], "Write Faild:" + Encoding.ASCII.GetString(operateResult2.Content, 1, operateResult2.Content.Length - 1));
					}
					else
					{
						result = OperateResult.CreateSuccessResult();
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 远程Run操作
		/// </summary>
		/// <param name="station">当前PLC的站号信息</param>
		/// <param name="readCore">通信的载体信息</param>
		/// <returns>是否成功</returns>
		// Token: 0x06000872 RID: 2162 RVA: 0x0002DA0C File Offset: 0x0002BC0C
		public static OperateResult RemoteRunHelper(byte station, Func<byte[], byte, OperateResult<byte[]>> readCore)
		{
			OperateResult<byte[]> operateResult = readCore(Encoding.ASCII.GetBytes("1001000000010000"), station);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				bool flag2 = operateResult.Content[0] != 6 && operateResult.Content[0] != 2;
				if (flag2)
				{
					result = new OperateResult((int)operateResult.Content[0], "Faild:" + Encoding.ASCII.GetString(operateResult.Content, 1, operateResult.Content.Length - 1));
				}
				else
				{
					result = OperateResult.CreateSuccessResult();
				}
			}
			return result;
		}

		/// <summary>
		/// 远程Stop操作
		/// </summary>
		/// <param name="station">当前PLC的站号信息</param>
		/// <param name="readCore">通信的载体信息</param>
		/// <returns>是否成功</returns>
		// Token: 0x06000873 RID: 2163 RVA: 0x0002DAA0 File Offset: 0x0002BCA0
		public static OperateResult RemoteStopHelper(byte station, Func<byte[], byte, OperateResult<byte[]>> readCore)
		{
			OperateResult<byte[]> operateResult = readCore(Encoding.ASCII.GetBytes("100200000001"), station);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				bool flag2 = operateResult.Content[0] != 6 && operateResult.Content[0] != 2;
				if (flag2)
				{
					result = new OperateResult((int)operateResult.Content[0], "Faild:" + Encoding.ASCII.GetString(operateResult.Content, 1, operateResult.Content.Length - 1));
				}
				else
				{
					result = OperateResult.CreateSuccessResult();
				}
			}
			return result;
		}

		/// <summary>
		/// 读取PLC的型号信息
		/// </summary>
		/// <param name="station">当前PLC的站号信息</param>
		/// <param name="readCore">通信的载体信息</param>
		/// <returns>返回型号的结果对象</returns>
		// Token: 0x06000874 RID: 2164 RVA: 0x0002DB34 File Offset: 0x0002BD34
		public static OperateResult<string> ReadPlcTypeHelper(byte station, Func<byte[], byte, OperateResult<byte[]>> readCore)
		{
			OperateResult<byte[]> operateResult = readCore(Encoding.ASCII.GetBytes("01010000"), station);
			bool flag = !operateResult.IsSuccess;
			OperateResult<string> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<string>(operateResult);
			}
			else
			{
				bool flag2 = operateResult.Content[0] != 6 && operateResult.Content[0] != 2;
				if (flag2)
				{
					result = new OperateResult<string>((int)operateResult.Content[0], "Faild:" + Encoding.ASCII.GetString(operateResult.Content, 1, operateResult.Content.Length - 1));
				}
				else
				{
					result = OperateResult.CreateSuccessResult<string>(Encoding.ASCII.GetString(operateResult.Content, 11, 16).TrimEnd(new char[0]));
				}
			}
			return result;
		}

		/// <summary>
		/// 将命令进行打包传送
		/// </summary>
		/// <param name="mcCommand">mc协议的命令</param>
		/// <param name="station">PLC的站号</param>
		/// <returns>最终的原始报文信息</returns>
		// Token: 0x06000875 RID: 2165 RVA: 0x0002DBEC File Offset: 0x0002BDEC
		public static byte[] PackCommand(byte[] mcCommand, byte station = 0)
		{
			byte[] array = new byte[13 + mcCommand.Length];
			array[0] = 5;
			array[1] = 70;
			array[2] = 57;
			array[3] = SoftBasic.BuildAsciiBytesFrom(station)[0];
			array[4] = SoftBasic.BuildAsciiBytesFrom(station)[1];
			array[5] = 48;
			array[6] = 48;
			array[7] = 70;
			array[8] = 70;
			array[9] = 48;
			array[10] = 48;
			mcCommand.CopyTo(array, 11);
			int num = 0;
			for (int i = 1; i < array.Length - 3; i++)
			{
				num += (int)array[i];
			}
			array[array.Length - 2] = SoftBasic.BuildAsciiBytesFrom((byte)num)[0];
			array[array.Length - 1] = SoftBasic.BuildAsciiBytesFrom((byte)num)[1];
			return array;
		}

		// Token: 0x0400021E RID: 542
		private byte station = 0;
	}
}
